﻿@model ProjectunitViewModel
@{
    Layout = null;
    ViewBag.Title = "安全考核被考核单位弹出框";
}
<div id="resultBox"></div>
<div style="float: left; display: block; margin: 8px; overflow: auto; width: 430px; height: 380px; border: solid 1px #CCC; line-height: 21px; background: #FFF;">
    
        <ul id="ctgl_kh_zTree" class="ztree"></ul>

</div>
<div class="formBar">
    <ul>
        <li>
            <button type="button" class="btn btn-xs" onclick="unitSel()">选择</button>
        </li>
        <li>
            <button type="button" class="close btn btn-default btn-xs">取消</button>
        </li>
    </ul>
</div>
<script type="text/javascript">
    var ctgl_kh_zTree;
    var setting = {
        treeObjId: "ctgl_kh_zTree",
        isSimpleData: true,              //数据是否采用简单 Array 格式，默认false
        treeNodeKey: "id",               //在isSimpleData格式下，当前节点id属性
        treeNodeParentKey: "pId",        //在isSimpleData格式下，当前节点的父节点id属性
        showLine: true,                  //是否显示节点间的连线
        checkable: true,                 //每个节点上是否显示 CheckBox
        callback: {
            nodeCreated: ctgl_kh_zTree_creat    //这是节点生成时的回调函数
        }
    };
    function ctgl_kh_zTree_creat(event, treeId, treeNode) {
        var section = $("#ctgl_kh_section").val();
        if (section.indexOf(treeNode.id) > 0 && treeNode.pId != null) {
            treeNode.checked = true;
            ctgl_kh_zTree.updateNode(treeNode, true);
        }
    }
    $(function () {
        var url = "/SafetyConstruction/ProjectSegment/GetSegmentLJson";
        if ($("#sel_item").val() == "1D6426E7-08CB-48F2-B11A-834389148D7C")
            url = "/SafetyConstruction/ProjectSegment/GetSupervJson";
        $.getJSON(
           url,
           function (data) {
               ctgl_kh_zTree = $("#ctgl_kh_zTree").zTree(setting, data);
               ctgl_kh_zTree.expandAll(true);
           });
    });

    function unitSel() {
        var unitCodes = "";
        var nodes = ctgl_kh_zTree.getCheckedNodes(true);
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].pId != null) {
                unitCodes += "'" + nodes[i].id + "',";
            }
        }
        $("#ctgl_kh_section").val(unitCodes);
        $.bringBack();
        $("#div_Units").loadUrl('/SafetyConstruction/ScmSafeAssessment/SafeAssessmentUnitSel', "type=" + $("#sel_item").val() + "&ucodes=" + escape($("#ctgl_kh_section").val()), null);
    }
</script>

